<div class="container">
    <div id="user_tb">
        #hasPermission("user:add")
            <a href="#" onclick="add()" class="easyui-linkbutton" data-options="iconCls:'fa fa-plus'">添加</a>
        #end
    </div>
    <div class="_datagrid">
        <table id="user_dg"></table>
    </div>
</div>
<script>
    var user_dg;
    $(function () {
        user_dg = $('#user_dg').datagrid({
            url: "#(ctx)/admin/user/userList",
            fitColumns: true,
            pagination: true,
            rownumbers: true,
            striped: true,
            singleSelect: true,
            pageSize: 10,
            pageList: [10, 20, 30],
            idField: 'userId',
            columns: [
                [{
                    field: 'userId',
                    width: 100,
                    hidden: true,
                    title: 'id'
                }, {
                    field: 'username',
                    title: '用户名',
                    width: 100
                }, {
                    field: 'password',
                    title: '密码',
                    width: 150
                }, {
                    field: 'userDesc',
                    title: '描述',
                    width: 120
                }, {
                    field: 'roleName',
                    title: '角色',
                    width: 100,
                }, {
                    field: 'delFlag',
                    title: '状态',
                    width: 100,
                    formatter: function (value, row, index) {
                        switch (value) {
                            case '0':
                                return '正常';
                            case '9':
                                return '锁定';
                        }
                    },
                }, {
                    field: 'createTime',
                    title: 'createTime',
                    width: 100
                }, {
                    field: '操作',
                    title: '操作',
                    width: 150,
                    formatter: function (value, row, index) {
                        var str = '';
                        #hasPermission("user:edit")
                            str += $.formatString('<a onclick="edit({0})" class="fa fa-pencil">修改</a>', row.userId);
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                        #end
                        #hasPermission("user:del")
                            str += $.formatString('<a onclick="del({0})" class="fa fa-remove">删除</a>', row.userId);
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                        #end
                        #hasPermission("user:lock")
                            str += $.formatString('<a onclick="lock({0})" class="fa fa-lock">锁定</a>', row.userId)
                        #end
                        return str;
                    }
                }]
            ],
            toolbar: '#user_tb'
        });
    })

    function edit(id) {
        parent.$.modalDialog({
            title: "编辑用户",
            width: 300,
            height: 300,
            href: "#(ctx)/admin/user/userEditPage/" + id,
            onLoad: function () {
                parent.$.modalDialog.openner_dataGrid = user_dg;
            }
        });
    }

    function add() {
        parent.$.modalDialog({
            title: "添加用户",
            width: 300,
            height: 300,
            href: "#(ctx)/admin/user/userAddPage",
            onLoad: function () {
                parent.$.modalDialog.openner_dataGrid = user_dg;
            }
        });
    }

    function del(id) {
        $.get('#(ctx)/admin/user/userDel/' + id, function (response) {
            if (response.result) {
                parent.$.messager.alert('提示', response.msg, 'info');
                user_dg.datagrid('reload');
            }
            progressClose();
        }, 'JSON');
    }

    function lock(id) {
        $.get('#(ctx)/admin/user/userLock/' + id, function (response) {
            if (response.result) {
                parent.$.messager.alert('提示', response.msg, 'info');
                user_dg.datagrid('reload');
            }
            progressClose();
        }, 'JSON');
    }
</script>